package com.cloud.code.真题;

import java.util.*;

/**
 * VLAN
 */
public class Demo8 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {

            String line = scanner.nextLine();
            int tar = Integer.parseInt(scanner.nextLine());

            Map<Integer, String> map = new TreeMap<>();
            String[] split = line.split(",");
            for (int i = 0; i < split.length; i++) {
                String s = split[i];
                if (s.contains("-")) {
                    String[] split1 = s.split("-");
                    map.put(Integer.valueOf(split1[0]), s);
                } else {
                    map.put(Integer.parseInt(s), null);
                }
            }

            List<Map.Entry<Integer, String>> list = new ArrayList<>(map.entrySet());
            int min = list.get(0).getKey();
            int max;
            Map.Entry<Integer, String> integerStringEntry = list.get(list.size() - 1);
            String value2 = integerStringEntry.getValue();
            if (value2 == null) {
                max = integerStringEntry.getKey();
            } else {
                max = Integer.parseInt(integerStringEntry.getValue().split("-")[1]);
            }

            if (tar >= min && tar <= max) {
                for (int i = 0; i < list.size(); i++) {
                    Map.Entry<Integer, String> integerStringEntry1 = list.get(i);
                    Integer key = integerStringEntry1.getKey();
                    String value1 = integerStringEntry1.getValue();
                    int end1 = -1;
                    if(value1 != null){
                        end1 = Integer.parseInt(value1.split("-")[1]);
                    }

                    if (key == tar && value1 == null) {
                        map.remove(key);
                    }

                    if (tar <= key || tar > key && tar < end1) {
                        Map.Entry<Integer, String> integerStringEntry2 = null;
                        if(tar < key){
                            integerStringEntry2 = list.get(i - 1);
                        }else {
                            integerStringEntry2 = list.get(i);
                        }
                        String value = integerStringEntry2.getValue();
                        Integer key1 = integerStringEntry2.getKey();
                        if (value != null) {
                            String[] split1 = value.split("-");
                            int start = Integer.parseInt(split1[0]);
                            int end = Integer.parseInt(split1[1]);

                            if (tar <= end) {
                                if(tar == end){
                                    if(start != end-1){
                                        map.put(key1,start+"-"+(end-1));
                                    }else {
                                        map.put(key1,null);
                                    }
                                }else {
                                    if(tar-start > 1 && end - tar > 1){
                                        map.put(start,start+"-"+(tar-1));
                                        map.put(tar+1,(tar+1)+"-"+end);
                                    }
                                    if(tar-start == 1 && end-tar>1){
                                        map.put(start,null);
                                        map.put(tar+1,(tar+1)+"-"+end);
                                    }

                                    if(tar-start > 1 && end-tar==1){
                                        map.put(start,start+"-"+(tar-1));
                                        map.put(tar+1,null);
                                    }
                                    if(tar == start && end-1 == start){
                                        map.remove(start);
                                        map.put(end,null);
                                    }

                                    if(tar == start && end-1 > start){
                                        map.remove(start);
                                        map.put(end,(tar+1)+"-"+end);
                                    }
                                }

                            }
                        }
                    }
                }
            }
            StringBuilder stringBuilder = new StringBuilder();
            map.forEach((integer, s) -> {
                if(s != null){
                    stringBuilder.append(s+",");
                }else {
                    stringBuilder.append(integer+",");
                }
            });

            System.out.println(stringBuilder.substring(0,stringBuilder.length()-1));
        }


    }
}
